package mapper;

import com.javabean.User;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.ArrayList;

public interface UserMapper {
    ArrayList<User> selectAll();

    @Select("<script> select * from user\n" +
            "        <where>\n" +
            "            <if test=\"uid!=0\">\n" +
            "                and uid=#{uid}\n" +
            "            </if>\n" +
            "            <if test=\"username!=null\">\n" +
            "                and username=#{username}\n" +
            "            </if>\n" +
            "            <if test=\"phone!=null\">\n" +
            "                and phone=#{phone}\n" +
            "            </if>\n" +
            "        </where></script>")
    ArrayList<User> selectUser(User user);




    @Select("select * from user")
    @Results(id ="u_r",value = {
            @Result(id = true,property = "uid",column = "uid"),
            @Result(property = "username",column = "username"),
            @Result(property = "password",column = "password"),
            @Result(property = "phone",column = "phone"),
            @Result(property = "r",column = "uid",one=@One(
                    select = "mapper.RoleMapper.SelectByUid",fetchType = FetchType.LAZY
            ))
    })
    ArrayList<User> selectU_R();

    
}
